
public class BinarySearchTree {
    static class TreeNode{
        public int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }

    }
    TreeNode root = null;
    public void insert(int val){
        if (root == null){
            root = new TreeNode(val);
            return;
        }
        TreeNode cur = root;
        TreeNode parent = null;
        while (cur != null){
            if (cur.val < val){
                parent = cur;
                cur = cur.right;
            }else if (cur.val == val){
                return;
            }else {
                parent = cur;
                cur = cur.left;
            }
        }
        TreeNode node = new TreeNode(val);
        if (parent.val < val){
            parent.right = node;
        }else {
            parent.left = node;
        }
    }
}
